package c.x.jy.wexin.controller;

import c.x.jy.common.utils.PageUtils;
import c.x.jy.common.utils.R;
import c.x.jy.dao.entity.NoticeEntity;
import c.x.jy.service.service.NoticeService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;


/**
 * 
 *
 * @author amwhyh
 * @email xxx@xx.com
 * @date 2021-05-31 12:32:03
 */
@RestController
@RequestMapping("wechat/notice")
public class NoticeController {
    @Autowired
    private NoticeService noticeService;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){

        PageUtils page = noticeService.queryPage(params);

        return R.put(page);
    }

    @RequestMapping("/getNew")
    public R getNew(Integer type){

//        PageUtils page = noticeService.queryPage(params);
        List<NoticeEntity> list = noticeService.getNew(type);
        return R.put(list);
    }
    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    public R info(@PathVariable("id") Long id){
		NoticeEntity notice = noticeService.getById(id);

        return R.put(notice);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("sys:notice:save")
    public R save(@RequestBody NoticeEntity notice){
		noticeService.save(notice);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("sys:notice:update")
    public R update(@RequestBody NoticeEntity notice){
		noticeService.updateById(notice);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete/{id}")
    @RequiresPermissions("sys:notice:delete")
    public R delete(@PathVariable("id") Long id){
		noticeService.removeByIds(Arrays.asList(id));

        return R.ok();
    }

}

